package NeuralAbstraction;

import DataAbstraction.Data;
import DataAbstraction.DataManager;
import NeuralAbstraction.NeuralNetwork.LearningAlgorithm;
import NeuralAbstraction.NeuralNetwork.NetworkType;

public abstract class NeuralManager {	
	private static NeuralNetwork instance = null;
	public static boolean isInstanceValid = false;
	
	


	public static void setMLPInstance(Data data, int[] layers, String name) throws Exception{		
		isInstanceValid = false;
		instance = new MLPNetwork(data.getInputData(), data.getOutputData(), layers, name);
		isInstanceValid = true;		
	}
	
	public static void setRBFInstance(Data data, int hiddenNeuronsCount, String name) throws Exception{		
		isInstanceValid = false;
		instance = new RbfNetwork(data.getInputData(), data.getOutputData(), hiddenNeuronsCount, name);
		isInstanceValid = true;		
	}
	
	public static NeuralNetwork getInstance(){		
		if (isInstanceValid)
			return instance;
		else
			return null;
	}
	
	public static int trainNetwork(LearningAlgorithm algo, double maxError) throws Exception{		
		if (!isInstanceValid)
			return -1;
		if (instance.getType() == NetworkType.MLP){
			return ((MLPNetwork)instance).trainNetwork(algo, maxError);
		} 
		else if (instance.getType() == NetworkType.RBF){
			return ((RbfNetwork)instance).trainNetwork(maxError);
		}			
		else return -1;
	}	

	
	public static void invalidateInstance(){
		isInstanceValid = false;
	}
	
}
